package edu.washington.cs.workflow.recommender;

import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

public class TestParsingTraceFileGantt extends TestCase {

	public void testCriticalPath() {
		String file = "./tests/files/gantt_critical_path_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "net.sourceforge.ganttproject.action.CalculateCriticalPathAction.actionPerformed(Ljava/awt/event/ActionEvent;)V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
		assertEquals(1, list.size());
	}
	
	public void testNextfile() {
		String file = "./tests/files/gantt_next_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "net.sourceforge.ganttproject.gui.scrolling.ScrollingManagerImpl.scrollBy(Lnet/sourceforge/ganttproject/task/TaskLength;)V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
		assertEquals(2, list.size());
	}
	
	public void testZoomIn() {
		String file = "./tests/files/gantt_zoom_in_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "net.sourceforge.ganttproject.gui.zoom.ZoomManager.fireZoomingChanged(II)V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
		assertEquals(1, list.size());
	}
	
	//
	//go to gantt2.0, ran ganttproject
	//java -cp .;./eclipsito.jar;../../bin;../../libs/simmetrics_jar.jar org.bardsoftware.eclipsito.Boot ganttproject-eclipsito-config.xml
	public void testGantt_zoom_in_out() {
		String file = "./tests/demo-traces/gantt_project_zoom_in_out_old_version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/gantt_zoom_in_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	public void testGantt_prev_next() {
		String file = "./tests/demo-traces/gantt_project_next_prev_old_version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/gantt_next_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	public void testGantt_critical_path() {
		String file = "./tests/demo-traces/gantt_project_critical_path_old_version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/gantt_critical_path_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	private void showInvokedHandlerAndActions(EventTraceProcessor oldProcessor, EventTraceProcessor newProcessor) {
		List<String> handlerDescs = oldProcessor.getAllUniqueActionHandlerDescs();
		for(String desc : handlerDescs) {
			System.out.println("-- handler : " + desc);
			System.out.println("      actions: " + newProcessor.getTriggeringActionDescs(desc));
			System.out.println("its invoked method: ");
			List<String> methods = oldProcessor.getInvokedMethodsByHandler(desc);
			for(String m : methods) {
				System.out.println("   " + m);
				//then query the 
				List<String> descs = newProcessor.getTriggeringActionDescs(m);
				System.out.println("      actions: " + descs);
				
			}
		}
	}
}
